var t = getApp();

Page({
    data: {
        scrollTop: 0,
        selected: 0,
        isLoadMore: !0,
        orderType: "pickup_card",
        detailUrl: "orderdetail",
        total_page: 0,
        page: 1,
        action: "",
        orderList: [],
        waitPayList: [],
        waitSendList: [],
        waitReceiveList: [],
        waitCompleteList: [],
        stopRefresh: !1,
        order_ids: [],
        isMultiplePay: !1,
        menu_group: {},
        plugin_name: "旅游激活卡",
        apiArr: [ "plugin.picking-card.frontend.PickingOrder.index", "plugin.picking-card.frontend.PickingOrder.waitSend", "plugin.picking-card.frontend.PickingOrder.waitReceive", "plugin.picking-card.frontend.PickingOrder.completed", "plugin.picking-card.frontend.PickingOrder.refund" ]
    },
    onLoad: function(t) {
        t.status && this.setData({
            selected: t.status
        }), t.plugin && "one" == t.plugin ? (wx.setNavigationBarTitle({
            title: "提货卡"
        }), this.setData({
            orderType: "picking-card-one"
        }), this.data.apiArr = [ "plugin.picking-card-one.frontend.PickingOrder.index", "plugin.picking-card-one.frontend.PickingOrder.waitSend", "plugin.picking-card-one.frontend.PickingOrder.waitReceive", "plugin.picking-card-one.frontend.PickingOrder.completed", "plugin.picking-card-one.frontend.PickingOrder.refund" ]) : wx.setNavigationBarTitle({
            title: "旅游激活卡订单"
        });
    },
    onReady: function() {},
    onShow: function() {
        this._getOrderList(this.data.selected);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.stopRefresh ? wx.stopPullDownRefresh() : (this._initData(), this._getOrderList(this.data.selected));
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData(this.data.page, this.data.selected) : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    _initData: function() {
        this.setData({
            isLoadMore: !0
        }), this.data.page = 1, this.data.total_page = 0;
    },
    _getOrderList: function(t) {
        this.data.action = this.data.apiArr[t], this._getNetData(this.data.action, t);
    },
    _getNetData: function(a, e) {
        var i = this, n = t.getNetAddresss(a);
        n += "&page=1", t._getNetWork({
            url: n,
            success: function(t) {
                var a = t.data;
                if (console.log(e, "测试"), 1 == a.result) {
                    var n = a.data;
                    i.setData({
                        menu_group: a.data.menu_group
                    }), i.data.total_page = n.total, 0 == e ? i.setData({
                        orderList: n.data
                    }) : 1 == e ? i.setData({
                        waitPayList: n.data
                    }) : 2 == e ? i.setData({
                        waitSendList: n.data
                    }) : 3 == e ? i.setData({
                        waitReceiveList: n.data
                    }) : 4 == e ? i.setData({
                        waitCompleteList: i.data.waitCompleteList.concat(n.data)
                    }) : i.setData({
                        waitRefund: n.data
                    });
                }
                wx.stopPullDownRefresh();
            },
            fail: function(t) {
                wx.stopPullDownRefresh(), console.log(t);
            }
        });
    },
    _getMoreData: function(a, e) {
        var i = this;
        if (!(this.data.page >= this.data.total_page)) {
            this.data.page = this.data.page + 1;
            var n = t.getNetAddresss(this.data.action);
            n += "&page=" + this.data.page, t._getNetWork({
                url: n,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        var n = a.data;
                        0 == e ? i.setData({
                            orderList: i.data.orderList.concat(n.data)
                        }) : 1 == e ? i.setData({
                            waitPayList: i.data.waitPayList.concat(n.data)
                        }) : 2 == e ? i.setData({
                            waitSendList: i.data.waitSendList.concat(n.data)
                        }) : 3 == e ? i.setData({
                            waitReceiveList: i.data.waitReceiveList.concat(n.data)
                        }) : 4 == e ? i.setData({
                            waitCompleteList: i.data.waitCompleteList.concat(n.data)
                        }) : i.setData({
                            waitRefund: i.waitRefund.concat(n.data)
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    swichTabTItem: function(t) {
        var a = t.detail.index;
        this.setData({
            selected: a
        }), this._initData(), this._getOrderList(this.data.selected);
    },
    onPageScroll: function(t) {
        this.setData({
            scrollTop: t.scrollTop
        });
    },
    stopRefresh: function(t) {
        var a = t.detail;
        this.setData({
            stopRefresh: a
        });
    },
    gotoPickUpCardMy: function() {
        wx.navigateTo({
            url: "/packageE/pickUpCard/pickUpCardMy/pickUpCardMy"
        });
    },
    multiplePayAction: function(t) {
        var a = t.detail;
        this.setData({
            order_ids: a
        }), a.length > 0 ? this.setData({
            isMultiplePay: !0
        }) : this.setData({
            isMultiplePay: !1
        });
    },
    gotoPickUpCard: function() {
        "picking-card-one" != this.data.orderType ? wx.navigateTo({
            url: "/packageE/pickUpCard/pickUpCardIndex/pickUpCardIndex"
        }) : wx.navigateTo({
            url: "/packageE/pickUpCard/pickUpCardIndex/pickUpCardIndex?plugin=one"
        });
    },
    toMultiplePay: function() {
        wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?order_id=" + this.data.order_ids.join(",") + "&status=2"
        });
    },
    cofirmOrderAction: function(t) {
        var a = t.detail;
        if (0 == this.data.selected) this._getOrderList(this.data.selected); else if ("pay" == a) this._getOrderList(this.data.selected); else {
            for (var e = this.data.waitReceiveList, i = 0; i < e.length; i++) a == e[i].id && e.splice(i, 1);
            this.setData({
                waitReceiveList: e
            });
        }
    }
});